﻿Imports System.Data.OleDb
Public Class commentOnCake
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If User.Identity.IsAuthenticated Then
            'Excellent no problem
        Else
            'Redirect to home
            Response.Redirect("opps.aspx?id=2")
        End If

        If Request.Params("cakeId") = Nothing Then
            Response.Redirect("opps.aspx?id=3")
        End If
    End Sub

    Protected Sub btn_comment_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_comment.Click
        Dim usernumber As Integer
        usernumber = Class1.getUserNumber(User.Identity.Name)


        Dim cn As Integer = Request.Params("cakeId")
        Dim SQL As String = "INSERT INTO CakeComment (C_FID,CommentBy,Comment) VALUES (@f1,@f2,@f3)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("CakeConnection").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(SQL, conn)
        cmd.Parameters.AddWithValue("@f1", cn)
        cmd.Parameters.AddWithValue("@f2", usernumber)
        cmd.Parameters.AddWithValue("@f3", tb_comment.Text)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()

        Class1.addCakePoint(usernumber, 1, "CakeComment")

        Response.Redirect("details.aspx?cakeNo=" & cn)


    End Sub
End Class